package cn.mesmile.auth.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.mesmile.auth.common.R;
import cn.mesmile.auth.service.UmsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zb
 * @date 2021/8/19 10:12
 * @Description
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UmsAdminService adminService;

//    @ApiOperation(value = "登录以后返回token")
    @PostMapping(value = "/login")
    public R login(@RequestParam String username, @RequestParam String password) {
        SaTokenInfo saTokenInfo = adminService.login(username, password);
        if (saTokenInfo == null) {
            return R.fail("用户名或密码错误");
        }
        return R.data(saTokenInfo);
    }

    @GetMapping(value = "/isLogin")
    public R isLogin() {
        return R.data(StpUtil.isLogin());
    }

    @GetMapping(value = "/logout")
    public R logout() {
        StpUtil.logout();
        return R.success("退出登录成功");
    }

}